package com.spring.boot.demo.controller;

import com.spring.boot.demo.pojo.User;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ZhuYouBin
 * @version 1.0.0
 * @Date: 2022/10/24 12:49
 * @Description
 */
@RestController
@RequestMapping("/api/swagger")
public class TestController {

    @ApiOperation(value = "新增用户")
    @PostMapping("/createUser")
    public String createUser(@RequestBody User user) {
        return "新增成功";
    }

    @ApiOperation(value = "新增用户信息")
    @PostMapping("/create")
    public String create(@ApiParam("用户名称") String username, @ApiParam("密码") String password) {
        System.out.println("username=" + username + ", password=" + password);
        return "新增成功";
    }

    @ApiOperation(value = "删除用户信息")
    @PostMapping("/delete")
    public String delete(String id) {
        System.out.println("id=" + id);
        return "删除成功";
    }

    @ApiOperation(value = "查询用户信息")
    @PostMapping("/query")
    public List<Map<String, String>> query() {
        List<Map<String, String>> maps = this.dataList();
        return maps;
    }

    private List<Map<String, String>> dataList() {
        // 模拟数据
        List<Map<String, String>> ans = new ArrayList<>();
        for (int i = 0; i < 4; i++) {
            Map<String, String> map = new HashMap<>();
            map.put("id", "00" + (i + 1));
            map.put("username", "uname-00" + i);
            map.put("password", "pass-00" + i);
            ans.add(map);
        }
        return ans;
    }

}
